package com.filmoc;

import javax.ejb.Local;
import javax.ejb.Stateless;
import java.util.List;
import javax.persistence.*;

@Stateless
@Local
public class UserEJB implements UserEJBRemote
{
	@PersistenceContext(unitName = "web")
	private EntityManager em;
	
	public List<User> findUser(){
		@SuppressWarnings("unchecked")
		TypedQuery<User> query = (TypedQuery<User>) em.createNativeQuery("findAllUsers", User.class);
		return query.getResultList();
			}
	
	public User findUserById(Long id) {
		return em.find(User.class, id);
	}
	public User createUser(User user) {
		em.persist(user);
		return user;
	}
	public void deleteUser(User user) {
		em.remove(user);
	}
	public User updateUser(User user) {
		return em.merge(user);
	}
}
